package com.top10.utils;

import java.util.UUID;

public class GetUuid {
    /** 新生成一个32位uuid */
    public String newId() {
        UUID uUID = UUID.randomUUID();
        long low = uUID.getLeastSignificantBits();
        long high = uUID.getMostSignificantBits();
        return (digits(high >> 32, 8) + digits(high >> 16, 4) + digits(high, 4) + digits(low >> 48, 4)
                + digits(low, 12));
    }
    /** uuid生产需要使用的函数 */
    private static String digits(long val, int digits) {
        long hi = 1L << (digits * 4);
        return Long.toHexString(hi | (val & (hi - 1))).substring(1);
    }
}
